*********************************************************************************
/*    Create time series plot for revenue, wages, and audit probability		*/
*********************************************************************************
clear all

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local graphpath "${graphpath}" 
local dofilepath "${mvpf_audits}/code/prep" 

* Version of fig to produce 
global version ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

* Audit type
if "`1'" == "nrp" local t = "nrp"
if "`1'" == "ops" local t = "ops"
if "`1'" == "both" local t = "ops nrp"
if "`1'" == "corr" local t = "corr"

local types "`t'"

use  "${mvpf_audits}/data/figures_rep/figure_3_ap10.dta", clear
/*------------------------------------------------------------------------------
Figure: Line audit prob, total rev, and audit wage costs by year (NRP & Ops) 
------------------------------------------------------------------------------*/
foreach type of local types{
	
	* exam type pooled
	if "`type'" == "nrp"{
		local i = 4
		global ytitle1 = "Percentage Change in Audit Rate (%)"
		local audit_rate = "audit_rate_round"
		
		* Audit prob range
		local lb_1 = 0.2
		local ub_1 = 1 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_1 = 0.2 //(`ub' - `lb')/5	
		
		* Rev/costs tot range
		local lb_2 = 0
		local ub_2 = 5000 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_2 = 1000 //(`ub' - `lb')/5	
	}
	
	if "`type'" == "ops"{
		local i = 1
		global ytitle1 = "Percentage Change in Audit Rate (%)"
		local audit_rate = "field_rate_round"
		
		* Audit prob range
		local lb_1 = 0.05
		local ub_1 = 0.25 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_1 = 0.05 //(`ub' - `lb')/5
		
		* Rev/costs tot range
		local lb_2 = 0
		local ub_2 = 16000 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_2 = 4000 //(`ub' - `lb')/5	
	}
	
		if "`type'" == "corr"{
		local i = 3
		global ytitle1 = "Percentage Change in Audit Rate (%)"
		local audit_rate = "corr_rate_round"
		
		* Audit prob range
		local lb_1 = 0.05
		local ub_1 = 0.25 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_1 = 0.05 //(`ub' - `lb')/5
		
		* Rev/costs tot range
		local lb_2 = 0
		local ub_2 = 1600 // round(`rev_tot_`hetlab''*1.13, 10) 
		local int_2 = 400 //(`ub' - `lb')/5	
	}
	
	local fig_name = "line_rc_prob_audit"
	local ylab = "Revenue / Cost"
	
	* R / C
	local lb_3 = 0
	local ub_3 = 4 // round(`rev_tot_`hetlab''*1.13, 10) 
	local int_3 = 1 //(`ub' - `lb')/5
	
*	
	* Plot 2: Audit probability + rev, cost over time
	tw  (connected roc primary_yr if exam_type_pooled == 1,  ///
		lc(gs11) mc(gs11) lp(shortdash) yaxis(1)) ///
		(connected roc_field primary_yr if exam_type_pooled == 1,  ///
		lc(gs4) mc(gs4) lp(longdash) yaxis(1) ///
		ytitle("${ytitle1}", axis(1)) ///
		ylabel(-50(10)0, nogrid format(%09.0fc) axis(1)) yscale(r())) ///
		///
		(connected rev_tot_disc primary_yr if exam_type_pooled == `i',  ///
		mc("0 114 178") lc("0 114 178") lp(solid) yaxis(2) ///
		ytitle("Dollars per Audit ($)", axis(2)) yscale(r(`lb_2' `ub_2') axis(2)) ///
		ylabel(`lb_2'(`int_2')`ub_2', nogrid format(%09.0fc) axis(2))) ///	
		(connected costs_labor_future primary_yr if exam_type_pooled == `i',  ///
		mc(cranberry) lc(cranberry) lp(solid) yaxis(2)) ///
		///
		, ///
		legend(off) ///
		${title} ${axis_size} ///
		xscale(r()) xtitle("Year") ///
		xlabel(, value labsize() tl() nogrid angle() )   
	graph export "`graphpath'/`fig_name'_`type'.wmf", replace
	
	li primary_yr roc roc_field

/*------------------------------------------------------------------------------
Figure: Line plot of hours worked and wages by year
------------------------------------------------------------------------------*/	
	* exam type pooled
	if "`type'" == "nrp"{
		local i = 4
	}
	
	if "`type'" == "ops"{
		local i = 1
	}
	

	* set y-axis label, title, and figure name
	local ylab = "Average value"
	

	* Preferences 
	local symbsize medsmall
	local textsize vsmall
	

	*** Subgroup figure
	local fig_name = "connected_hours_wages_year"
	
	if "`type'" == "ops"{
	local lb = 20
	local ub = 50 // round(`max', 100)
	local int = 6 // (`ub' - `lb')/5	
	}
	
	if "`type'" == "nrp"{
	local lb = 30
	local ub = 55 // round(`max', 100)
	local int = 5 // (`ub' - `lb')/5	
	}
	
	local lb_f : di %02.1f `lb'
	local ub_f : di %02.1f `ub'
	
	global oh_color = "240 128 128"

	tw  (connected hours_future primary_yr if exam_type_pooled == `i', ///
		mcolor("${oh_color}") lc("${oh_color}") msymbol(O) msize(`symbsize')) ///
		(connected wage primary_yr if exam_type_pooled == `i', ///
		mcolor(cranberry) lc(cranberry) msymbol(T) msize(small)) ///
		, ///
		///text(36 2011 "Auditor wage rate ($/hour)") ///
		///text(48 2011 "Hours per audit") ///
		ylabel(`lb'(`int')`ub', nogrid format(%9.0fc)) yscale(r(`lb_f' `ub_f')) ///
		ytitle("`ylab'") xtitle("${xtitle}")   ///
		legend(off) ///
		${title} ${axis_size} ///
		xscale(r()) xtitle("Year") ///
		xlabel(, value labsize() tl() nogrid angle() )  
	graph export "`graphpath'/`fig_name'_`type'.wmf", as(wmf) replace


*
/*------------------------------------------------------------------------------
Figure: Line plot of revenue over direct labor costs
------------------------------------------------------------------------------*/	
	
	* exam type pooled
	if "`type'" == "nrp"{
		local i = 4
	}
	
	if "`type'" == "ops"{
		local i = 1
	}
	

	* set y-axis label, title, and figure name
	local ylab = "Audit Revenue / Wage Costs"
	

	* Preferences 
	local symbsize medsmall
	local textsize vsmall
	

	*** Subgroup figure
	local fig_name = "connected_rc_labor_year"
	
	if "`type'" == "ops"{
	local lb = 8
	local ub = 14 // round(`max', 100)
	local int = 1 // (`ub' - `lb')/5	
	}
	
	if "`type'" == "nrp"{
	local lb = 0
	local ub = 6 // round(`max', 100)
	local int = 1 // (`ub' - `lb')/5	
	}
	
	local lb_f : di %02.1f `lb'
	local ub_f : di %02.1f `ub'
	
	global oh_color = "240 128 128"

	tw  (connected rc_labor primary_yr if exam_type_pooled == `i', ///
		mcolor("${rc_col}") lc("${rc_col}") msymbol(O) msize(`symbsize')) ///
		, ///
		ylabel(`lb'(`int')`ub', nogrid format(%9.0fc)) yscale(r(`lb_f' `ub_f')) ///
		ytitle("`ylab'") xtitle("${xtitle}")   ///
		legend(off) ///
		${title} ${axis_size} ///
		xscale(r()) xtitle("Year") ///
		xlabel(, value labsize() tl() nogrid angle() )  
	graph export "`graphpath'/`fig_name'_`type'.wmf", as(wmf) replace
}	